package com.swu.pad.event.controller;

import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.poi.ss.formula.functions.Even;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.swu.pad.event.entity.Event;
import com.swu.pad.event.entity.RftWritingEvent;
import com.swu.pad.event.service.EventService;
import com.swu.pad.system.entity.User;

@Controller
@RequestMapping(value = "/event")
public class EventController {
      
	@Autowired
	private EventService eventService;
   
	
	@ResponseBody
	@RequestMapping(value = "/saveUserEvent")
	public String saveUserEvent(String object,String  action,HttpSession session) {
 		Event event = new Event();
 		User user=(User) session.getAttribute("user");
 		event.setAction(action);
 		event.setActionTime(new Date());
 		event.setObject(object);
 		event.setUserId(user.getId());
 		eventService.saveUserEvent(event);
		return "success";
	}
	

	@ResponseBody
	@RequestMapping(value = "/getUserEvents")
	public List<Event> getUserEvents(String userID) {
		return eventService.getUserEvents(userID);
	}
	
	@ResponseBody
	@RequestMapping(value = "/saveRftWritingEvent")
	public String saveRftWritingEvent(RftWritingEvent rftWritingEvent) {
		 eventService.saveRftWritingEvent(rftWritingEvent);
		 return "success";
	}
	
}

